//
//  EmployeeCardViewController.m
//  MyProject
//
//  Created by 石小强 on 2018/4/18.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "EmployeeCardViewController.h"

@interface EmployeeCardViewController ()

@end

@implementation EmployeeCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    
    NSString *version = [UIDevice currentDevice].systemVersion;
    if (version.doubleValue >= 11.0) {
        self.backBtnTopHeight.constant = 0;
    } else {
        // 针对 9.0 以下的iOS系统进行处理
        self.backBtnTopHeight.constant = 20;
    }
    
    if ([Tool isIphoneX]) {
        self.sharePictureBottomHeight.constant = 157;
    } else {
        self.sharePictureBottomHeight.constant = 113;
    }
    
    
    [self setupSubViews];
    
//    [self getIncumbentStateOfAuthentication];
}

- (void)setupSubViews {
    self.headerIV.layer.cornerRadius = 34.5;
    self.headerIV.layer.masksToBounds = YES;
    
    [self.headerIV sd_setImageWithURL:ImageURLWithKey(self.model.headImg) placeholderImage:PlaceholderImage];
    self.nameL.text = self.model.nickName;
    
    NSInteger authenticationNum = 0;
    if (self.model.companyInfo.realNameAuthentication) {
        authenticationNum += 1;
    }
    if (self.model.companyInfo.companyEamilAuthentication) {
        authenticationNum += 1;
    }
    if (self.model.companyInfo.incumbentAuthentication) {
        authenticationNum += 1;
    }
    if (self.model.companyInfo.laborContractAuthentication) {
        authenticationNum += 1;
    }
    if (self.model.companyInfo.employeeCardAuthentication) {
        authenticationNum += 1;
    }
    if (authenticationNum > 0) {
        self.certificateL.text = @"台阶认证";
    } else {
        self.certificateL.text = @"未认证";
    }
    
    NSDateFormatter *ft = [[NSDateFormatter alloc] init];
    [ft setDateFormat:@"YYYY"];
    NSDate *dateNow = [NSDate date];
    NSString *currentTimeStr = [ft stringFromDate:dateNow];
    NSInteger time = [currentTimeStr integerValue] - [self.model.companyInfo.entryTime integerValue];
    
    
    self.positionYearL.text = [NSString stringWithFormat:@"%@ | 已在职%zd年", self.model.companyInfo.jobName, time];
    self.companyL.text = self.model.companyInfo.companyName;
    
    // 删除领域
    NSArray *skills = [self.model.adeptSkill componentsSeparatedByString:@","];
    NSString *skillResult = @"";
    if (skills.count > 0) {
        for (NSString *str in skills) {
            skillResult = [NSString stringWithFormat:@"%@、%@", skillResult, str];
        }
    }
    self.skillsL.text = skillResult.length > 0 ? [skillResult substringFromIndex:1] : @"";
    
    // 帮助过多少人
    self.helpPeopleCountL.text = [NSString stringWithFormat:@"帮助过%@人 | 满意度", self.model.helpedCount];
    
    // 满意度
    self.starView.value = [self getStarWithSatisfaction:self.model.degreeOfSatisfaction];
    
    CGFloat itemH = (kScreenWidth - 52) * 439 / 323;
    
    self.imageBackViewLineTopHeight.constant = 250 * itemH / 439;
}

// 获取认证信息
- (void)getIncumbentStateOfAuthentication {
    WS(weakSelf)
    [self showProgressWithView:self.view animated:YES];
    [SendRequest getIncumbentStateOfAuthenticationWithResult:^(NSDictionary *result, NSError *error) {
        [weakSelf hideProgress:self.view animated:YES];
        result = [CommonUtils decryptDicWithResult:result];
        if([result[@"result"] integerValue] == 1) {
            SaintiLog(@"认证信息 = %@", [result objectForKey:@"data"]);
            BOOL state = [[[result objectForKey:@"data"] objectForKey:@"state"] boolValue];

            if (state) {
                weakSelf.certificateL.text = @"台阶认证";
            } else {
                weakSelf.certificateL.text = @"未认证";
            }
        } else {
            [CommonUtils showToast:[result objectForKey:@"msg"]];
        }
    }];
}

- (IBAction)starViewClick:(id)sender {
    self.starView.value = [self getStarWithSatisfaction:self.model.degreeOfSatisfaction];
}

- (IBAction)backBtnClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)mainBtnClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 微信分享
- (IBAction)weixinBtnClick:(id)sender {
    [self showShareViewWithView:self.imageBackView type:SSDKPlatformSubTypeWechatSession];
}

#pragma mark - 朋友圈分享
- (IBAction)pengyouquanBtnClick:(id)sender {
    [self showShareViewWithView:self.imageBackView type:SSDKPlatformSubTypeWechatTimeline];
}

#pragma mark - QQ分享
- (IBAction)qqBtnClick:(id)sender {
}

#pragma mark - 微博分享
- (IBAction)weiboBtnClick:(id)sender {
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}


- (CGFloat)getStarWithSatisfaction:(NSString *)degreeOfSatisfaction {
    CGFloat result = [degreeOfSatisfaction floatValue];
    
    if (result >= 0 && result < 0.25) {
        return 0;
    } else if (result >= 0.25 && result < 0.75) {
        return 0.5;
    } else if (result >= 0.75 && result < 1.25) {
        return 1;
    } else if (result >= 1.25 && result < 1.75) {
        return 1.5;
    } else if (result >= 1.75 && result < 2.25) {
        return 2;
    } else if (result >= 2.25 && result < 2.75) {
        return 2.5;
    } else if (result >= 2.75 && result < 3.25) {
        return 3;
    } else if (result >= 3.25 && result < 3.75) {
        return 3.5;
    } else if (result >= 3.75 && result < 4.25) {
        return 4;
    } else if (result >= 4.25 && result < 4.75) {
        return 4.5;
    } else {
        return 5;
    }
    
}

@end
